package com.bweab.controll.depositcontroll;

import com.bweab.pojo.DepositTb;
import com.bweab.service.api.DepositTbServiceInterface;
import com.bweab.service.impl.DepositTbServiceInterfaceImpl;
import com.bweab.util.JSONResult;
import com.bweab.util.JSONStats;
import com.bweab.util.WebUtil;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
@WebServlet("/queryDepositById")
public class QueryDepositById extends HttpServlet {

    //创建服务对象
    DepositTbServiceInterface depositTbService =new DepositTbServiceInterfaceImpl();
    //创建返回结果
    JSONResult jsonResult =new JSONResult();
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        int depositId = Integer.parseInt(req.getParameter("depositId"));
        //调用服务层
        DepositTb depositInfo = depositTbService.getDepositById(depositId);

        if(depositInfo!=null){
            //如果获取到的信息不是空
                    //设置响应信息
            //查询失败
            jsonResult.setData(depositInfo);
            jsonResult.setStatusCode(JSONStats.QUERY_SUCCESS.getStatusCode());
            jsonResult.setMessage(JSONStats.QUERY_SUCCESS.getMessage());
        }else {
            //查询失败
            jsonResult.setMessage(JSONStats.QUERY_ERROR.getMessage());
            jsonResult.setStatusCode(JSONStats.QUERY_ERROR.getStatusCode());
        }

        WebUtil.writeJson(resp,jsonResult);

    }
}
